﻿
using System;
using Microsoft.Owin;
using Microsoft.Owin.Security;
using Sharp.Portal.Mvc.OAuth.Sharp;

// ReSharper disable CheckNamespace

namespace Owin
{
    public static class SharpAuthenticationExtensions
    {
        public static void UseSharpAuthentication(this IAppBuilder app, SharpAuthenticationOptions options)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            app.Use(typeof(AuthenticationMiddleware), app, options);
        }

        public static void UseSharpAuthentication(this IAppBuilder app, string clientId, string clientSecret)
        {
            UseSharpAuthentication(app, new SharpAuthenticationOptions()
            {
                ClientId = clientId,
                ClientSecret = clientSecret,
                SignInAsAuthenticationType = app.GetDefaultSignInAsAuthenticationType()
            });
        }
    }
}
